package com.xique.door.project.sfm.controller;

import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.door.project.sfm.bean.request.SfmInsertPeopleRequest;
import com.xique.door.project.sfm.bean.request.SfmOpenDoorRequest;
import com.xique.door.project.sfm.bean.request.SfmSelectHouseRequest;
import com.xique.door.project.sfm.biz.service.ISfmHomeBizService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/sfm/home")
public class SfmHomeController extends BaseController {

    @Autowired
    private ISfmHomeBizService sfmHomeBizService;

    @GetMapping("/getProvince")
    public AjaxResult getProvince() {
        //返回{\"province_no\":\"12\",\"province_name\":\"安徽省\"}
        return sfmHomeBizService.getProvince();
    }

    @GetMapping("/getCity")
    public AjaxResult getCity(@RequestParam("provinceNo") String provinceNo) {
        //返回 \"city_no\":\"99\",\"city_name\":\"芜湖市\"
        return sfmHomeBizService.getCityByProvinceNo(provinceNo);
    }

    @GetMapping("/getCommunityByCity")
    public AjaxResult getCommunityByCity(@RequestParam("provinceNo") String provinceNo,@RequestParam("cityNo")String cityNo) {
        //返回 data":[{"community_no":"1632794798752673","community_name":"芜湖市弋江区中央城D区","community_address":"安徽省芜湖市弋江区花津南路39号"},
        // {"community_no":"1635590032234426","community_name":"芜湖市弋江区中央城A区","community_address":"安徽省芜湖市弋江区"},
        // {"community_no":"1635816388059350","community_name":"芜湖市弋江区中央城C区","community_address":"安徽省芜湖市弋江区"}]}
        return sfmHomeBizService.getCommunityByCity(provinceNo,cityNo);
    }

    @GetMapping("/getBuildingByCommunityNo")
    public AjaxResult getBuildingByCommunityNo(@RequestParam("communityNo") String communityNo) {
        //eg:测试communityNo=1632794798752673
        //返回 {\"building_no\":\"1632813642597219\",\"building_number\":\"0011\",\"building_name\":\"D1栋1单元\"}
        return sfmHomeBizService.getBuildingByCommunityNo(communityNo);
    }

    @GetMapping("/getHouseByBuildingNo")
    public AjaxResult getHouseByBuildingNo(@RequestParam("buildingNo") String buildingNo,@RequestParam("communityNo") String communityNo) {
        //eg:测试communityNo=1632794798752673 buildingNo=1632813642597219
        //返回{"house_no":"1633769902962399","house_number":"0301","house_name":"0301"},
        return sfmHomeBizService.getHouseByBuildingNo(buildingNo,communityNo);
    }

    @GetMapping("/getListByHouseNo")
    public AjaxResult getListByHouseNo(@RequestParam("houseNo") String houseNo, @RequestParam("communityNo") String communityNo,
                                       @RequestParam("pageindex") String pageindex, @RequestParam("pagesize") String pagesize) {
        //eg:测试communityNo=1632794798752673 houseNo=1633769902962399
        //返回data:[{"people_no":"1648802239413258","people_name":"王美凤","people_photo":"http://sfm-passweb.oss-cn-shenzhen.aliyuncs.com/1648802239543696.jpg?Expires=4804475839&OSSAccessKeyId=LTAIIux1rFeEycax&Signature=VFZmNYA3%2F4VPSwiW3w3llDKwTPc%3D","people_idcard":"1648802239413258","people_phone":"15905532692","people_type":"其它"},
        // {"people_no":"1644320353037182","people_name":"单宏","people_photo":"http://sfm-passweb.oss-cn-shenzhen.aliyuncs.com/1644320353112860.jpg?Expires=4805489457&OSSAccessKeyId=LTAIIux1rFeEycax&Signature=dFiLnWWLyl9cpUasN7%2BVO1WkToI%3D","people_idcard":"1644320353037182","people_phone":"15305531680","people_type":"家人"},
        // {"people_no":"1644317990383860","people_name":"单倩雅","people_photo":"http://sfm-passweb.oss-cn-shenzhen.aliyuncs.com/1644320791568447.jpg?Expires=4805489457&OSSAccessKeyId=LTAIIux1rFeEycax&Signature=636eHldAQQTwxw3FRmpOZbTalSw%3D","people_idcard":"1644317990383860","people_phone":"17755360708","people_type":"家人"},
        // {"people_no":"1641607475770288","people_name":"单倩雅","people_photo":"http://sfm-passweb.oss-cn-shenzhen.aliyuncs.com/1644320651779705.jpeg?Expires=4805489129&OSSAccessKeyId=LTAIIux1rFeEycax&Signature=ygNcpIKQblhUViOZlrMGj7r%2Fdhk%3D","people_idcard":"1641607475770288","people_phone":"17755360708","people_type":"家人"},
        // {"people_no":"1641607449902308","people_name":"单宏","people_photo":"http://sfm-passweb.oss-cn-shenzhen.aliyuncs.com/1644320470231109.jpeg?Expires=4805489129&OSSAccessKeyId=LTAIIux1rFeEycax&Signature=NGhrj84A7%2FC7ohNRHeiWMRCOKzI%3D","people_idcard":"1641607449902308","people_phone":"15305531680","people_type":"家人"},
        // {"people_no":"1641607412096524","people_name":"彭剑岚","people_photo":"http://sfm-passweb.oss-cn-shenzhen.aliyuncs.com/5c8f1223-d733-43c0-903a-f2d829fbd122_1641607412096524_1.jpg?Expires=4805489129&OSSAccessKeyId=LTAIIux1rFeEycax&Signature=b5Q6dLQ8qw6fJGhv0%2FuC8IGKwHA%3D","people_idcard":"1641607412096524","people_phone":"13305537789","people_type":"业主"}]
        return sfmHomeBizService.getListByHouseNo(houseNo, communityNo, pageindex, pagesize);
    }

    @PostMapping("/insertPeople")
    public AjaxResult insertPeople(@RequestBody @Valid SfmInsertPeopleRequest request) {
        return sfmHomeBizService.insertPeople(request);
    }

    @DeleteMapping("/deletePeople")
    public AjaxResult deletePeople(@RequestParam("peopleNo") String peopleNo, @RequestParam("communityNo") String communityNo) {
        return sfmHomeBizService.deletePeople(peopleNo, communityNo);
    }

    @GetMapping("/getDeviceList")
    public AjaxResult getDeviceList(@RequestParam("peopleNo") String peopleNo, @RequestParam("communityNo") String communityNo,
                                    @RequestParam("pageindex") String pageindex, @RequestParam("pagesize") String pagesize) {
        //eg:测试communityNo=1632794798752673 peopleNo=1641607412096524
        //返回data:[{"device_no":"220211258467D","device_category":"人脸设备终端","device_type":"墙外机","device_name":"D区东入口辅助","device_area":"D区东入口辅助","device_enable":1,"device_outintype":1,"buildingno":""},
        // {"device_no":"2202112116027","device_category":"人脸设备终端","device_type":"墙外机","device_name":"D区西入口辅助","device_area":"D区西入口辅助","device_enable":1,"device_outintype":1,"buildingno":""},
        // {"device_no":"211215010872E","device_category":"人脸设备终端","device_type":"楼栋机","device_name":"D1栋1单元","device_area":"D1栋1单元","device_enable":1,"device_outintype":1,"buildingno":"1632813642597219"},
        // {"device_no":"2110271768559","device_category":"人脸设备终端","device_type":"墙外机","device_name":"D区北面东侧消防门","device_area":"D区北面东侧消防门","device_enable":1,"device_outintype":1,"buildingno":""},
        // {"device_no":"2110271784680","device_category":"人脸设备终端","device_type":"墙外机","device_name":"D区北面中央消防门","device_area":"D区北面中央消防门","device_enable":1,"device_outintype":1,"buildingno":""},
        // {"device_no":"810025b0d8f12565","device_category":"人脸设备终端","device_type":"墙外机","device_name":"D区东门入口","device_area":"D区东门入口","device_enable":1,"device_outintype":1,"buildingno":""},
        // {"device_no":"15c47ee916fa71da","device_category":"人脸设备终端","device_type":"墙外机","device_name":"D区西门入口","device_area":"D区西门入口","device_enable":1,"device_outintype":1,"buildingno":""}]
        return sfmHomeBizService.getDeviceList(peopleNo, communityNo, pageindex, pagesize);
    }

    @PostMapping("/openDoor")
    public AjaxResult openDoor(@RequestBody @Valid SfmOpenDoorRequest request) {
        return sfmHomeBizService.openDoor(request);
    }

    @PostMapping("/selectHouse")
    public AjaxResult selectHouse(@RequestBody @Valid SfmSelectHouseRequest request) {
        return sfmHomeBizService.selectHouse(request);
    }

    @GetMapping("/getUserInfo")
    public AjaxResult getUserInfo(@RequestParam("phone") String phone) {
        return sfmHomeBizService.getUserInfo(phone);
    }
}
